# encoding: utf-8
import requests


class MyHeaders(object):
    def items(self):
        return (('Host', 'match.yuanrenxue.com'),
                ('Connection', 'keep-alive'),
                ('Content-Length', '0'),
                ('Pragma', 'no-cache'),
                ('Cache-Control', 'no-cache'),
                ('sec-ch-ua', '"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"'),
                ('sec-ch-ua-mobile', '?0'),
                ('User-Agent', 'yuanrenxue.project;'),
                ('Accept', '*/*'),
                ('Origin', 'http://match.yuanrenxue.com'),
                ('Sec-Fetch-Site', 'same-origin'),
                ('Sec-Fetch-Mode', 'cors'),
                ('Sec-Fetch-Dest', 'empty'),
                # ('X-Requested-With', 'XMLHttpRequest'),
                ('Referer', 'http://match.yuanrenxue.com/match/3'),
                ('Accept-Encoding', 'gzip, deflate,br'),
                ('Accept-Language', 'zh-CN,zh;q=0.9'),
                ('Cookie', kk[0]),)


kk = ';'
num = {}
for i in range(1, 6):
    r = requests.post('https://match.yuanrenxue.com/jssm', headers=MyHeaders())
    kk = r.headers['Set-Cookie'].split(';')
    r1 = requests.get('https://match.yuanrenxue.com/api/match/3?page=' + str(i), headers=MyHeaders()).json()
    print(r1)
    for j in r1['data']:
        if str(j['value']) not in num:
            num[str(j['value'])] = 1
        else:
            num[str(j['value'])] = num[str(j['value'])] + 1
print(num)
